package com.example.lenovo.demo;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.lenovo.demo.presenter.UserAcPresenter;
import com.example.lenovo.demo.presenter.adapter.User_VpAdapter;
import com.example.lenovo.demo.view.UserFgManager;
import com.example.lenovo.demo.view.ifgview.IUserActivity;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

@ContentView(R.layout.activity_user)
public class UserActivity extends AppCompatActivity implements IUserActivity {
    @ViewInject(R.id.user_tb)
    private Toolbar toolbar;
    @ViewInject(R.id.user_vp)
    private ViewPager viewpager;
    @ViewInject(R.id.user_tab)
    private TabLayout tabLayout;
    @ViewInject(R.id.user_ctb)
    private CollapsingToolbarLayout collapsingToolbarLayout;
    private User_VpAdapter adapter;
    private List<Fragment> lists;
    private String[] arr;
    @ViewInject(R.id.user_title_name)
    private TextView tv1;
    @ViewInject(R.id.user_likes_tv)
    private TextView tv2;
    @ViewInject(R.id.user_img)
    private ImageView iv1;
    @ViewInject(R.id.user_title_img)
    private ImageView iv2;
    private String id;
    private UserAcPresenter userAcPresenter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        initData();
    }

    private void initData() {
        lists = new ArrayList<>();
        Intent intent = getIntent();
        id =intent.getStringExtra("id");
        arr = getResources().getStringArray(R.array.user_str);
        toolbar.setEnabled(true);
        for (int i = 0; i < arr.length; i++) {
            lists.add(UserFgManager.getFragment(arr[i]));
        }
        setSupportActionBar(toolbar);
        //设置返回按钮
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        adapter = new User_VpAdapter(getSupportFragmentManager(), lists, arr);
        tabLayout.setupWithViewPager(viewpager);
        //设置tablayout与viewPager
        viewpager.setAdapter(adapter);
        userAcPresenter = new UserAcPresenter(this);
        userAcPresenter.initData();

    }

    @Override
    public TextView getTvOne() {
        return tv1;
    }

    @Override
    public TextView getTvTwo() {
        return tv2;
    }

    @Override
    public ImageView getImgOne() {
        return iv1;
    }

    @Override
    public ImageView getImgTwo() {
        return iv2;
    }

    @Override
    public String getID() {
        return id;
    }

    @Override
    public Context getUserContext() {
        return this;
    }
}
